﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>最佳女王瑜伽培训</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <link rel="stylesheet" href="/styles/swiper.min.css">
    <style>
        .swiper-pagination-bullet {
            width: 8px;
            height: 8px;
            display: inline-block;
            border-radius: 100%;
            background: #ffffff;
            opacity: .2;
        }

        .swiper-pagination-bullet-active {
            opacity: 1;
            background: #f1f2f3;
        }
    </style>
    <style>
        body {
            margin: 0px;
            padding: 0px;
            background-color: #f5f5f5;
        }

        .titleContent {
            padding: 10px 0px;
            background-color: rgba(0,0,0,1);
            border-bottom: 0px solid #ddd;
            margin: 0px;
            position: fixed;
            top: 0px;
            width: 100%;
            min-height: 18px;
            z-index: 2;
        }

        #title {
            background-image: url(../images/back.png);
            background-repeat: no-repeat;
            color: #fff;
            font-size: 16px;
            text-align: center;
            font-weight: bold;
            height: 18px;
        }

        #content {
            overflow: hidden;
            padding: 2px;
            margin-top: 40px;
            overflow-x: hidden;
            padding: 0px 5px;
        }

        .is-loading {
            background-color: #fff;
            background-image: url(images/load.gif);
            background-repeat: no-repeat;
            background-position: center;
            border-radius: 3px;
            border: 1px solid #ddd;
            padding: 3px;
            background-color: #eee;
        }



        .msg {
            text-align: center;
            color: #888;
            font-size: 12px;
            padding: 5px;
            display: none;
        }

        .more {
            text-align: center;
            padding: 10px;
            color: #ff0000;
            border: 1px solid #eee;
            margin-top: 5px;
        }

        .item {
            margin-top: 10px;
            overflow: hidden;
            position: relative;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
            min-height: 100px;
            background-image: url(../images/load.gif);
            background-repeat: no-repeat;
            background-position: center;
        }

        .item_flag {
            padding: 5px;
            background-color: rgba(254, 255, 254,0.5);
            border: 1px solid #ddd;
            border-radius: 3px;
            color: #FF5722;
            max-width: 60px;
            position: absolute;
            top: 10px;
            right: 10px;
        }

        .item_content {
            position: absolute;
            background-color: rgba(254, 255, 254,0.5);
            bottom: 10px;
            height: 84px;
            width: 100%;
            text-align: center;
        }

        .item_title {
            font-size: 16px;
            font-weight: bold;
            padding: 5px;
            border-bottom: 0px solid #ddd;
            width: 90%;
            margin: 0px auto;
        }

        .item_text {
            line-height: 22px;
            color: #fff;
            overflow: hidden;
            margin-top: 50px;
        }




        .swiper-slide {
            line-height: 300px;
            color: #fff;
            font-size: 36px;
            text-align: center;
            background: #000;
        }

        .swiper-loading {
            background-image: url(../images/loadForShowImg.gif);
            background-repeat: no-repeat;
            background-position: center;
        }
    </style>
    <style>
        .ptRow {
            border-bottom: 1px solid #e2dfdf;
            padding: 10px 0px;
        }

            .ptRow .des {
                padding: 0px;
                font-size: 14px;
                color: #555;
                line-height: 20px;
            }

            .ptRow .imgCt {
                display: inline-block;
                overflow: hidden;
                border: 0px solid #5c0260;
                background-color: #fff;
                background-image: url(../images/newLoad.gif);
                background-repeat: no-repeat;
                background-position: center;
                margin-left: 1px;
            }

                .ptRow .imgCt img {
                }
    </style>

</head>
<body>

   <div class="loading" style="background-color: rgba(255, 255, 255, 0.8); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000; background-image: url(&quot;&quot;); background-position: center center; background-repeat: no-repeat; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background-size: 50px;"></div>
    <div class="titleContent" onclick="window.history.back();">
        <div id="title">
            训练照展示
        </div>
    </div>

    <div id="content">
        <div id="newContent" style="display:none;">

        </div>
        <div class="msg">加载中……</div>
        <div class="more" style="display:none;">显示更多>></div>
    </div>


    <div id="showPhoto" style="position:absolute;top:0px;background:#000;width:100%;z-index:3;display:none;">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide swiper-loading"><img src="../files/upload/newsImageAdd(2017-6-29191012381)_24323432.jpg" style="width:100%;" /></div>
                <div class="swiper-slide swiper-loading"><img src="../files/upload/newsImageAdd(2017-6-29181042417)_portal.jpg" style="width:100%;" /></div>
                <div class="swiper-slide swiper-loading"><img src="../files/upload/newsImageAdd(2017-6-29185815961)_333.jpg" style="width:100%;" /></div>
            </div>
            <div class="swiper-pagination"></div>
        </div>
    </div>

    <script src="/js/lib/jquery.js"></script>
    <script src="/js/lib/swiper.min.js"></script>
    <script type="text/javascript">
        $("#showPhoto").css("display", "block");
        var mySwiper = new Swiper('.swiper-container', {
            //loop: true,
            //autoplay: 3000,
            preloadImages: false,
            speed: 200,
            effect: 'cube',           
            observer: true,
            observeParents: true,
            lazyLoading: true,
            pagination: '.swiper-pagination',
        });
        $("#showPhoto").css("display", "none");


        var pageIndex = 0;
        var busy = 0;
        var resultList = [];
        function getproductList() {
            if (busy == 2) return;
            busy = 1;
            pageIndex++;

            var Jsondata = {};
            Jsondata.pageIndex = pageIndex;
            Jsondata.pageSize = 3;
            $(".more").hide();
            $.post('/admin/getproducts', JSON.stringify(Jsondata), function (response) {
                if (response.length == 0) {
                    $(".more").hide();
                    busy = 2;
                    return;
                }
                $(".msg").show();
                var template=' <div class="ptRow">'
                + '<div class="des">{{content}}</div>'
                + '<div>{{theImages}}</div>'
                + '</div> ';

                var imgItem = '<div class="imgCt" onclick="imgClick(\'{{id}}\',{{index}})" style={{imgCt}}><img src="../files/upload/xsmall/{{image}}" style="{{imgStyle}}" /></div>';


                var resultHTML = "";
                for (i = 0; i < response.length; i++) {
                    var o = response[i];
                    var tempHtml =template;
                    tempHtml = tempHtml.replace("{{content}}", o.description);
                    var imgResult = "";
                    var num = o.images.length;
                    for (j = 0; j < num; j++) {
                        var no = o.images[j];
                        o.images[j].index = j;
                        var nt = imgItem;
                        nt = nt.replace("{{id}}", o._id);
                        nt = nt.replace("{{image}}", no.filename);
                        nt = nt.replace("{{index}}", j.toString());

                        //计算图片高度、宽度、上偏移
                        var scWidth = $(window).width();
                        var wt = 0;
                        var ht = 0;
                        var marginTop = 0;
                        var wtPercent = 100;
                        var marginLeft = 0;
                        if (num == 1) {
                            wt = 150;
                            if (scWidth < 150) wt = scWidth - 40;
                            ht = wt / no.width * no.height;
                        }
                        else{
                            wt = (scWidth - 40) / 3;
                            ht = wt;
                            var imgHt = wt / no.width * no.height;
                            if (imgHt < wt) {
                                wtPercent = parseInt(wt / imgHt * 100) + 3;
                                marginLeft = parseInt((wtPercent/100*wt-wt)/2)/-1;
                            }
                            else {
                                marginTop = parseInt((imgHt - ht) / 2) / -1;
                            }
                        }
                        var imgCtStyle = 'width:' + wt.toString() + 'px;height:' + ht.toString() + 'px;';
                        var imgStyle = 'width:' + wtPercent .toString()+ '%;margin-top:' + marginTop.toString() + 'px;margin-left:' + marginLeft.toString() + "px;";

                        nt = nt.replace("{{imgCt}}", imgCtStyle);
                        nt = nt.replace("{{imgStyle}}", imgStyle);
                       

                        if ((num == 2 || num == 4)&&(j==1||j==3)) {
                            nt += "<span style='display:block;height:0px;'></span>";
                        }
                        imgResult += nt;
                    }

                    tempHtml = tempHtml.replace("{{theImages}}", imgResult);
                    resultHTML += tempHtml;
                    resultList.push(o);
                }
                $("#newContent").append(resultHTML);
				$(".msg").hide();
                $(".more").show();
				if(pageIndex==1){
                   $("#newContent").show();
				  setTimeout(function () {                     				
                    $(".loading").hide(); 										
                    }, 1000); 
				}
                busy = 0;
                console.log(resultList);
            })
        }
        var scrollTop = 0;
        function imgClick(id,index) {
            var height = $(window).height();
            var width = $(window).width();
            var template = '<div class="swiper-slide swiper-loading" style="height:525px;overflow:hidden;"><img src="../files/upload/small/{{image}}" style="width:100%;margin-top:{{marginTop}};" /></div>';
            var o = null;
            for (i = 0; i < resultList.length; i++) {
                if (id == resultList[i]._id) o = resultList[i];
            }


            var tImages = [];            
            for (k = 0; k < o.images.length; k++) {
                for (i = 0; i < o.images.length; i++) {
                    if (k == o.images[i].index) tImages.push(o.images[i]);
                }
            }
            console.log(tImages);
            var tempHtml = "";
            mySwiper.removeAllSlides();
            for (j = 0; j < tImages.length; j++) {
                var t=template;
                var ob = tImages[j];
                var marginTop = 0;
                var smallHeight = 400.00 / ob.width * ob.height;
                var imgHeight = width / 400.00 * smallHeight;
                if (width > 400) imgHeight = smallHeight;

                if (imgHeight < height) marginTop = (height - imgHeight) / 2.0+10;

                t = t.replace("{{image}}", ob.filename).replace("{{marginTop}}", marginTop.toString() + "px");
                //tempHtml+=t;
                mySwiper.appendSlide(t);
            }
            mySwiper.update(true);
            
            setTimeout(function () {
                mySwiper.slideTo(index,0,false);
            },10)
            
            //$(".swiper-wrapper").html(tempHtml);
            $("#showPhoto").css("min-height", height.toString() + "px");
            $("#showPhoto").css("display", "block");
            scrollTop=$(document).scrollTop();
            $("#content").hide();
            return false;
        }




        $(function () {
            $('.page-loading').delay(0).fadeOut(1000);
            getproductList();


            $("#showPhoto").click(function () {
                $("#content").show();
                $(this).fadeOut();
                var odiv = document.getElementsByTagName('body')[0];
                odiv.scrollTop = scrollTop;
            });

            $(".more").click(function () { getproductList(); });
            $(window).bind("scroll", function (e) {
                var ScrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
                if (busy == 2) return;
                if (ScrollBottom < 100) {
                    if (busy == 1) return;
                    getproductList();
                }
            });

        });
    </script>

</body>

</html>
